package _1域对象;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/test2")
public class Test2Servlet extends HttpServlet {

	int count4 = 0;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		int count3 = 0;
		count3++;
//		System.out.println("test2 count3:"+count3+"<br />");
		resp.getWriter().print("test2 count3:" + count3 + "<br />");

		count4++;

		resp.getWriter().print("test2 count4:" + count4 + "<br />");

		// 得到上下文对象
		ServletContext context = this.getServletContext();
		// 取信息
		Integer allCount = (Integer) context.getAttribute("allCount");
		if (allCount == null) {
			allCount = 0;
		}
		allCount++;
		// 存入信息
		context.setAttribute("allCount", allCount);

		resp.getWriter().print("all count:" + allCount + "<br />");
	}
}